<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">

        // 3.要求输入一串低于10位的数字，输出对应的中文大写:
        //替换
        var num = prompt('请输入一个数字');
        var up = '零一二三四五六七八九';
        var str = num.toString();
        var str2 = '';
        for (let index = 0; index < str.length; index++) {
            for (let index2 = 0; index2 < up.length; index2++) {
                if (str[index] == index2) {
                    str2 += up[index2];
                }
            }
        }




        //反转
        var temp = str2.split('');
        str2 = (temp.reverse()).join('');




        //拼接单位
        var final = '';

        const unit = ['十','百','千','万','万十','万百','万千','亿','亿十','亿百','亿千']

        //去零
        var zero = '一';
        if (str2[0]=='零') {
            zero = '零'
        }


        for (let index = 0; index < str2.length; index++) {
            if (index == str2.length-1) {
                final += str2.slice(index)
            }else{
                if (str2[index+1]=='零') {
                    if (zero!='零') {
                        final += str2.slice(index,index+1)
                    }
                    zero = str2[index+1]
                }else{
                    final += str2.slice(index,index+1) + unit[index]
                    zero = '一';
                }
            }
        }

        //回转
        temp = final.split('');
        var count0 = 0;
        final = (temp.reverse()).join('');

        //去除尾数零
        if (final[final.length-1]=='零') {
            final = final.slice(0,final.length-1)
        }
        
        document.write(final);